<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%" v-loading="loading">
      <el-table-column label="海报">
        <template slot-scope="scope">
          <div class="aa">
            <img :src="scope.row.poster" alt height="70px" width="70px">
          </div>
        </template>
      </el-table-column>
      <el-table-column header-align="center" prop="name" align="center" label="电影名"></el-table-column>
      <el-table-column header-align="center" prop="category" align="center" label="类型"></el-table-column>
      <el-table-column header-align="center" prop="nation" align="center" label="国家"></el-table-column>
      <el-table-column header-align="center" prop="runtime" align="center" label="时长"></el-table-column>
      <el-table-column header-align="center" prop="language" align="center" label="语言"></el-table-column>
      <el-table-column header-align="center" prop="grade" align="center" label="评分"></el-table-column>
      <el-table-column header-align="center" align="center" label="操作">
        <template slot-scope="scope">
          <!-- scope.row是本行对应的数据 -->
          <router-link :to="`/film/edit/${scope.row.filmId}`">
            <el-button type="text" size="small">编辑</el-button>
          </router-link>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-row v-if="value">
      <el-pagination
        @current-change="changepage"
        :page-size="pageSize"
        layout="prev, pager, next"
        :total="total"
        class="pagination"
      ></el-pagination>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: false,
      loading: false,
      tableData: [],
      pageNum: 1,
      pageSize: 10,
      total: 0
    };
  },
  created() {
    this.getlist(this.pageNum);
  },
  methods: {
    async getlist(pageNum) {
      let url = "http://132.232.87.95:3000/admin/film/getList";
      this.loading = true;
      try {
        let res = await this.axios.post(url, {
          pageSize: this.pageSize,
          pageNum
        });
        this.loading = false;
        this.total = res.data.total;
        this.tableData = res.data.films;
        // console.log("films", res.data.films);
      } catch (error) {
        this.loading = false;
      }
      if (this.total > this.pageSize) {
        this.value = true;
      }
    },
    async changepage(pageNum) {
      let dete = await this.getlist(pageNum);
    },
     //删除
   async handleDelete(index, row) {
      let btn = confirm("是否要删除");
      if (btn == true) {
        let url = "/film/delById";
        let res =await this.$axios.post(url, row);
        this.tableData.splice(index, 1);
        this.$message({
          message: "删除成功"
        });
      } else {
      }
    }
  }
};
</script>
<style>
.aa {
  height: 100px !important;
}
</style>